import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import {library} from '@fortawesome/fontawesome-svg-core';
import {fas} from '@fortawesome/free-solid-svg-icons'
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome';
import type {MorghulisOptions} from "./types/tool/channel.types.ts";
import MDialog from "./components/dialog/MDialog.vue";
import {loadMorghulisSockets} from "./hooks/socket.ts";
import DTable from "./components/table/data/DTable.vue";
import MTable from "./components/table/MTable.vue";
import MForm from "./components/form/MForm.vue";
import DCell from "./components/table/data/DCell.vue";
import DForm from "./components/table/data/DForm.vue";
import DTableController from "./components/table/data/DTableController.vue";
import MCell from "./components/cell/MCell.vue";

// 导入样式文件
import './style.css'

// 导出组件
export { default as MTable } from './components/table/MTable.vue';
export { default as MDialog } from './components/dialog/MDialog.vue';
export { default as MForm } from './components/form/MForm.vue';
export { default as DTable } from './components/table/data/DTable.vue';
export { default as DCell } from './components/table/data/DCell.vue';
export { default as DForm } from './components/table/data/DForm.vue';
export { default as DController } from './components/table/data/DTableController.vue';
export { default as MCell } from './components/cell/MCell.vue';

// 导出hooks
export { useMorghulisAuthorize } from './hooks/authorize';
export { useMorghulisChannel } from './hooks/channel';
export { useMorghulisSockets, loadMorghulisSockets } from './hooks/socket';
export { useMorghulisRequest } from './hooks/request';
export { useMorghulisCookies } from './hooks/cookies';

library.add(fas);

export const createMorghulis = (options?: MorghulisOptions) => {
    options = options || {baseURL: '/api/', minioURL: '/dfs/'}
    const baseURL = options.baseURL as string
    const sockets = loadMorghulisSockets(baseURL)
    return {
        install: (Vue: any) => {
            Vue.provide('options', options)
            Vue.provide('sockets', sockets)
            Vue.component('MTable', MTable)
            Vue.component('MDialog', MDialog)
            Vue.component('MForm', MForm)
            Vue.component('DTable', DTable)
            Vue.component('DCell', DCell)
            Vue.component('DForm', DForm)
            Vue.component('DController', DTableController)
            Vue.component('MCell', MCell)
            Vue.use(ElementPlus, {locale: zhCn})
            Vue.component('fa', FontAwesomeIcon)
        }
    }
}